package main

import (
	"fmt"
	"time"
)

/*func main() {
	v := []int{1, 2, 3}
	for i := range v {
		v = append(v, i)
	}
	fmt.Println(v)
}

//输出结果：[1 2 3 0 1 2]*/

func main() {

	var m = [...]int{1, 2, 3}

	//1
	//输出
	//0 1
	//1 2
	//2 3
	//for i, v := range m {
	//	go func() {
	//		fmt.Println(i, v)
	//	}()
	//}

	//2
	//for i, v := range m {
	//	go func(i, v int) {
	//		fmt.Println(i, v)
	//	}(i, v)
	//}

	//3
	for i, v := range m {
		i := i // 这里的 := 会重新声明变量，而不是重用
		v := v
		go func() {
			fmt.Println(i, v)
		}()
	}

	time.Sleep(time.Second * 3)
}
